package main

import (
	"log"
	"runtime"
	"time"
)

func main() {
	// demo1()
	// demo2()
}

// go + 匿名函数
func demo1() {
	go func() {
		sum := 0
		for i := 0; i < 1000; i++ {
			sum += i
		}
		log.Println(sum)
		time.Sleep(1 * time.Second)
	}()

	log.Println("正在运行的线程", runtime.NumGoroutine())
	time.Sleep(5 * time.Second)
}

// go + 有名函数
func demo2() {
	go demo3()

	log.Println("正在运行的线程", runtime.NumGoroutine())
	time.Sleep(5 * time.Second)
}

func demo3() {
	sum := 0
	for i := 0; i < 1000; i++ {
		sum += i
	}
	log.Println(sum)
	time.Sleep(1 * time.Second)
}
